/*
 * Project: D-Link TR-069
 * 
 * File:   data.h
 * 
 * Authors: Taron Sargsyan	
 * 	    Suren Gharagyozyan	
 *
 * Created on September 20, 2011, 11:53 AM
 * 
 * 
 * This object is useful to create interface with ACS_Server(tr069 server) and tr069 client 
 * e.g. Reading  datas(XMLs) from tr069 client, parsing it, chekking in D-Base and adding values in D-Base   
 * 
 * Copyright (C) 2011 D-Link Company.  All rights reserved.
 */

#ifndef _SERVHELPER_H_
#define _SERVHELPER_H_


#define FILE_MSG_SIZE  50000 //30000
#define READ_MSG_SIZE  4096

#define SUCCESS  1
#define FAILURE -1



#define ONE_BOOT         strcmp((char*)getTags(fileCBuff[i].fileContBuff,"EventCode",1),"1 BOOT")
#define ZERO_BOOTSTRAP   strcmp((char*)getTags(fileCBuff[i].fileContBuff,"EventCode",1),"0 BOOTSTRAP")
#define TWO_PERIODIC     strcmp((char*)getTags(fileCBuff[i].fileContBuff,"EventCode",1),"2 PERIODIC")
#define FOR_VALUE_CHANGE strcmp((char*)getTags(fileCBuff[i].fileContBuff,"EventCode",1),"4 VALUE CHANGE")
#define END_XML_FILE_DL	 find_string(fileCBuff[i].fileContBuff,"</soapenv:Envelope>", 0)
#define END_XML_FILE_DU	 find_string(fileCBuff[i].fileContBuff,"</SOAPENV:Envelope>", 0)
#define END_XML_FILE_U   find_string(fileCBuff[i].fileContBuff,"</SOAP-ENV:Envelope>", 0)
#define END_XML_FILE_L	 find_string(fileCBuff[i].fileContBuff,"</soap-env:Envelope>", 0)
#define END_XML_FILE     (END_XML_FILE_U > 0 || END_XML_FILE_L > 0 || END_XML_FILE_DU > 0 || END_XML_FILE_DL > 0)
#define ZERO_CONTENT     find_string(fileCBuff[i].fileContBuff,"Content-Length: 0",0)
#define GET_PARAM_NAME_RESP       find_string(fileCBuff[i].fileContBuff,"GetParameterNamesResponse", 0)
#define GET_RPC_METHODS_RESP      find_string(fileCBuff[i].fileContBuff,"<cwmp:GetRPCMethods>", 0)
#define SET_PARAMETER_VALUES_RESP find_string(fileCBuff[i].fileContBuff,"<cwmp:SetParameterValuesResponse>", 0) 

#define MODEL_NAME    fileCBuff[i].get_val[get_index(fileCBuff[i].get_names,"InternetGatewayDevice.DeviceInfo.ModelName")].getValueStr 
#define SERIAL        fileCBuff[i].get_val[ get_index(fileCBuff[i].get_names,"InternetGatewayDevice.DeviceInfo.SerialNumber")].getValueStr 
#define MANUFACT      fileCBuff[i].get_val[ get_index(fileCBuff[i].get_names,"InternetGatewayDevice.DeviceInfo.Manufacturer")].getValueStr 
#define OUI           fileCBuff[i].get_val[ get_index(fileCBuff[i].get_names,"InternetGatewayDevice.DeviceInfo.ManufacturerOUI")].getValueStr 
#define PRODUCT_CLASS fileCBuff[i].get_val[ get_index(fileCBuff[i].get_names,"InternetGatewayDevice.DeviceInfo.ProductClass")].getValueStr

#define MODEL_NAME_FIRST (char*)getTags(fileCBuff[i].fileContBuff,"Value",1) 

#define SET_PARAM_FAILUR find_string(fileCBuff[i].fileContBuff,"<faultcode>", 0)
#define SET_PARAM_FAILUR_NUM (char*)getTags(fileCBuff[i].fileContBuff,"faultcode",1)
#define SET_PARAM_ANSWER (char*)getTags(fileCBuff[i].fileContBuff,"Status",1)

#define GET_PARAM_VALUE_RESPONSE find_string(fileCBuff[i].fileContBuff,"<cwmp:GetParameterValuesResponse>",0)
#define FIND_FIRST_MODEL_PARAM_NAME find_string(fileCBuff[i].fileContBuff,"InternetGatewayDevice.DeviceInfo.ModelName",0)


#define GET_REBOOT strcmp((char*)getTags(fileCBuff[i].fileContBuff,"EventCode",1),"M Reboot")

#define FIND_WRITABLE find_string(fileCBuff[i].fileContBuff,"Writable",0)
#define GET_STATUS find_string(fileCBuff[i].fileContBuff,"<Status>",0)
#define M_DOWNLOAD strcmp((char*)getTags(fileCBuff[i].fileContBuff,"EventCode",1),"M Download")
#define HAVE_DATA (find_string(fileCBuff[i].fileContBuff,"SOAP-ENV",0) > 0 || find_string(fileContBuff,"soap-env",0) > 0 )
#define TRANSFER_COMPLETE strcmp((char*)getTags(fileCBuff[i].fileContBuff,"EventCode",1),"7 TRANSFER COMPLETE") == 0



char *cpe_model_Name;
char *cpe_serial;
char *cpe_manufact;
char *cpe_oui;
char *cpe_product_class;

// char model_name[32];
char status_buff[1];

int out_get_param_value0;
int out_get_param_value1;

int c_reboot;
int c_download;

char buffer[READ_MSG_SIZE];

char xmlFile[FILE_MSG_SIZE];
char* notChange;
char have_fw_upgrade[1024];

int sendFile,i,any_cpe_connect;
fd_set active_fd_set, read_fd_set;
int clientsock[10];



void send_recive_socket( int);
int read_from_client ( int );
void send_response( char[] );
int sendall( char[] );

void write_to_file( char* fileCont );

#endif